#include "stdafx.h"
#include "CRangeControl.h"


CRangeControl::CRangeControl()
	: m_fMin(0.0f), m_fMax(100.0f), m_fValue(50.0f)
{

}

CRangeControl::CRangeControl(int_32 iX, int_32 iY, int_32 iWidth, int_32 iHeight)
	: CControl(iX, iY, iWidth, iHeight), m_fMin(0.0f), m_fMax(100.0f), m_fValue(50.0f)
{

}
CRangeControl::~CRangeControl()
{

}

void CRangeControl::SetMinValue(float_32 fMin)
{
	if(fMin > m_fValue)
		throw CIllegalArgumentException();

	if(!Float32Equal(fMin, m_fMin))
	{
		m_fMin = fMin;
		Repaint();
	}
}

float_32 CRangeControl::GetMinValue() const
{
	return m_fMin;
}

void CRangeControl::SetMaxValue(float_32 fMax)
{
	if(fMax < m_fValue)
		throw CIllegalArgumentException();

	if(!Float32Equal(fMax, m_fMax))
	{
		m_fMax = fMax;
		Repaint();
	}
}

float_32 CRangeControl::GetMaxValue() const
{
	return m_fMax;
}

void CRangeControl::SetValue(float_32 fValue)
{
	if(fValue < m_fMin)
		fValue = m_fMin;
	else if(fValue > m_fMax)
		fValue = m_fMax;
	else {}

	if(!Float32Equal(fValue, m_fValue))
	{
		m_fValue = fValue;
		Repaint();
	}
}

float_32 CRangeControl::GetValue() const
{
	return m_fValue;
}

void CRangeControl::SetRangeInfo(float_32 fMin, float_32 fMax, float_32 fValue)
{
	if((fMin > fMax) || (fValue < fMin) || (fValue > fMax))
		throw CIllegalArgumentException();

	if(!Float32Equal(fMin, m_fMin) || !Float32Equal(fMax, m_fMax) || !Float32Equal(fValue, m_fValue))
	{
		m_fMin = fMin;
		m_fMax = fMax;
		m_fValue = fValue;
		Repaint();
	}
}

void CRangeControl::SetRangeInfo(const RangeInfo & range)
{
	SetRangeInfo(range.MinValue, range.MaxValue, range.Value);
}

void CRangeControl::GetRangeInfo(float_32 * pfMin, float_32 * pfMax, float_32 * pfValue) const
{
	VerifyPointer(pfMin);
	VerifyPointer(pfMax);
	VerifyPointer(pfValue);

	*pfMin = m_fMin;
	*pfMax = m_fMax;
	*pfValue = m_fValue;
}

RangeInfo CRangeControl::GetRangeInfo() const
{
	return RangeInfo(m_fMin, m_fMax, m_fValue);
}

float_32 CRangeControl::GetRate() const
{
	return (m_fValue - m_fMin) / (m_fMax - m_fMin);
}
